package com.itheima.service.impl;

import com.itheima.mapper.KeywordMapper;
import com.itheima.pojo.Keyword;
import com.itheima.service.KeywordService;
import com.itheima.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class KeywrodServiceImpl implements KeywordService {
    @Override
    public List<Keyword> find(String keyword) {
        SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();
        //2. 获取SqlSession
        SqlSession sqlSession = factory.openSession();
        //3. 获取DishMapper
        KeywordMapper mapper = sqlSession.getMapper(KeywordMapper.class);
        //4. 调用方法
        List<Keyword> list = mapper.find("%" + keyword + "%");
        //释放资源
        sqlSession.close();
        return list;
    }
}
